package cn.shyouchi.wuguanjia.android.ui.event.proprietor;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.model.OwnerEntity;
import cn.shyouchi.wuguanjia.android.utils.LogUtil;
import cn.shyouchi.wuguanjia.android.widget.GlideCircleTransform;

/**
 * Created by Eenie on 2016/10/25 at 16:51
 * Email: 472279981@qq.com
 * Des:
 */

public class ProprietorAdapter extends BaseQuickAdapter<OwnerEntity.ProprietorBean,BaseViewHolder> {

    private ProprietorInfoContract.View mView;

    private final String BASE_URL = "http://118.178.88.132:8000";




    public ProprietorAdapter(List<OwnerEntity.ProprietorBean> data, ProprietorInfoContract.View view) {
        super(R.layout.item_event_proprietor_layout, data);
        this.mView = view;
    }

    @Override
    protected void convert(BaseViewHolder holder, final OwnerEntity.ProprietorBean entity) {
        holder.setText(R.id.tv_proprietor_name, TextUtils.isEmpty(entity.getName()) ? "暂无姓名" : entity.getName());
        ImageView imgHeader = holder.getView(R.id.img_header);

        bindImg(mContext, entity.getImages(), imgHeader);

        holder.getView(R.id.btn_del).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mView.onDelClick(entity);
            }
        });
        holder.getView(R.id.item_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.e("click");
                mView.onItemClick(entity);
            }
        });
    }


    public void bindImg(Context context, String path, ImageView iv) {
        if (!TextUtils.isEmpty(path)) {
            path = BASE_URL + path;
        }

        Glide.with(context)
                .load(path)
                .placeholder(R.mipmap.ic_default_header)
                .transform(new GlideCircleTransform(context))
                .into(iv);
   }
}
